home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
Z4CXEX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-26
|
5KB
|
150 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: z4cxex.c
// Title: ZIP+4 Engine
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains the expander for the city cross reference file.
// This module should not use any global variables since it must be
// re-entrant.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <z4.h>
//----------------------------------------------------------------------------
// Description: Read a compressed record from the output buffer.
// Parameters: pblk Decoder data structure
// pctyst ZIP5 record
// Returns: TRUE if successful.
// FALSE if no more records found to decode.
//----------------------------------------------------------------------------
BOOL FN_E Z4CXExpand(PZ4_CX_BLK pblk, PZ4_CX pcx)
{
PBYTE pb;
SIZET cb, cLen;
Assert(pblk && pcx);
memset(&pblk->cx, 0, sizeof(pblk->cx));
// Must be at end of buffer
if (pblk->cbNext + 2 + sizeof(USHORT) + MAX_ZIP5_BCD >= pblk->cb)
return FALSE;
pb = pblk->pb + pblk->cbNext; // Decode ZIP5
if (pb[0] == 0) // Block not full, but no more records
{
pblk->cbNext = pblk->cb;
return FALSE;
}
pblk->cx.state = (Z4_STATE)*pb; // Get state
pb++;
cLen = strlen((PSZ)pb); // Get city name
memcpy(pblk->cx.szCity, pb, cLen + 1);
pb += cLen + 1;
cLen = strlen((PSZ)pb); // Get po name
memcpy(pblk->cx.szPO, pb, cLen + 1);
pb += cLen + 1;
// Number of POF's
pblk->cx.cFinance = (SIZET)*(PUSHORT)pb;
pb += sizeof(USHORT);
// List of POF's
cb = MAX_FINANCE_BCD * pblk->cx.cFinance;
memcpy(pblk->cx.abFinance, pb, cb);
pb += cb;
// Number of 5 digit ZIPs
pblk->cx.cZip5 = (SIZET)*(PUSHORT)pb;
pb += sizeof(USHORT);
// List of 5 digit ZIPs
cb = MAX_ZIP5_BCD * pblk->cx.cZip5;
memcpy(pblk->cx.abZip5, pb, cb);
pb += cb;
cb = (SIZET)(pb - pblk->pb);
Assert(cb <= pblk->cb);
pblk->cbNext = cb;
*pcx = pblk->cx; // Return a copy of the current record
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Initialize expander
// Parameters: pblk Decoder data structure
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E Z4CXExpandInitialize(PZ4_CX_BLK pblk)
{
Assert(pblk);
memset(pblk, 0, sizeof(Z4_CX_BLK));
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Reset expander to decode another block of data.
// Parameters: pblk Decoder data structure
// pb Buffer containing compressed data.
// cb Size of buffer.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E Z4CXExpandReset(PZ4_CX_BLK pblk, PBYTE pb, SIZET cb)
{
Assert(pblk);
pblk->pb = pb; // Set decoding pointers
pblk->cb = cb;
pblk->cbNext = 0;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Terminate expander.
// Parameters: pblk Decoder data structure
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E Z4CXExpandTerminate(PZ4_CX_BLK pblk)
{
Assert(pblk);
memset(pblk, 0, sizeof(Z4_CX_BLK));
return TRUE;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------